﻿using University.Workshop.Business;
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.Tests
{
    [TestClass]
    public class RatingsTests
    {
        [TestMethod]
        public void SuccesfullRating()
        {
            Rating rate1 = new Rating();
            rate1.Rate = 3;
            rate1.UserId = 2;
            rate1.ProductId = 1;
            rate1.Date = DateTime.Now;
            RatingDataAccess.InsertRating(rate1);
            Assert.AreEqual(1, rate1.ProductId);
        }

        [TestMethod]
        public void UserAlreadyRatedProve()
        { 
            Rating rate1 = new Rating();
            rate1.Rate = 3;
            rate1.UserId = 2;
            rate1.ProductId = 1;
            rate1.Date = DateTime.Now;
            RatingDataAccess.InsertRating(rate1);
            bool res = RatingDataAccess.UserAlreadyRated(rate1);
            Assert.IsTrue(res);
        }

        [TestMethod]
        public void GettingAverageTest()
        {
            Rating rate1 = new Rating();
            rate1.Rate = 3;
            rate1.UserId = 1;
            rate1.ProductId = 1;
            rate1.Date = DateTime.Now;
            RatingDataAccess.InsertRating(rate1);
            decimal res = RatingDataAccess.GetProductRatingsAverage(1);
            Assert.AreEqual(3, res);
        }

        [TestMethod]
        public void InsertFeedback()
        {
            Rating rate1 = new Rating();
            rate1.Rate = 40;
            rate1.UserId = 2;
            rate1.ProductId = 1;
            rate1.Date = DateTime.Now;
            rate1.Comment = "Is very good seller and the time of shipping was good";
            rate1 = RatingDataAccess.InsertUserRating(rate1);
            Assert.AreEqual(1, rate1.ProductId);
        }

        [TestMethod]
        public void GetSum()
        {
            Rating rate1 = new Rating();
            rate1.Rate = 40;
            rate1.UserId = 2;
            rate1.ProductId = 1;
            rate1.Date = DateTime.Now;
            rate1.Comment = "GOOD SELLER";
            rate1 = RatingDataAccess.InsertUserRating(rate1);
            decimal res = RatingDataAccess.GetUserRatingsSum(1);
            Assert.IsTrue(res>=40);
        }
    }
}
